﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PMS.Server.Entities;
using PMS.Server.IService;

namespace PMS.Server.Service
{
    public class ContractService : IContractService
    {
        ISqlSugarClient _client;
        public ContractService(ISqlSugarClient client)
        {
            _client = client;
        }

        public ContractEntity[] GetDatas(string key, DateTime start, DateTime end, int index, int size, ref int totalCount)
        {
            return _client.Queryable<ContractEntity>()
                        .Where(ce =>
                            ce.SignTime >= start && ce.SignTime <= end
                            &&
                            (string.IsNullOrEmpty(key) ||
                            ce.ContractName.Contains(key) ||
                            ce.ContractNumber.Contains(key) ||
                            ce.Opposite.Contains(key))
                        )
                        .ToPageList(index, size, ref totalCount)
                        .ToArray();
        }
    }
}
